package com.example.flutter_plugin

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity : FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        /* Handler().postDelayed({
             startActivity(Intent(this, PluginActivity::class.java))
         }, 1000)*/
    }

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)

        val plugin1 = MyFlutterPlugin1()
        plugin1.iPluginCallback = object : IPluginCallback {
            override fun onPluginCallback(methodChannel: MethodChannel, call: MethodCall) {
                // flutter 调用 android 插件中的方法的名称
                val method = call.method
                if (method == "method1") {
                    startActivity(Intent(context, PluginActivity::class.java))
                }
            }
        }
        //val plugin2 = MyFlutterPlugin2()

        // 注册自定义插件，用于演示 flutter 与 android 原生之间的数据通信
        flutterEngine.plugins.add(plugin1)

        // 注册自定义插件，用于演示 flutter 使用 android 原生控件，并做数据通信
        //flutterEngine.plugins.add(plugin2)

        GeneratedPluginRegistrant.registerWith(flutterEngine)
    }
}
